package com.kexio.scheduler.entity;

import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.kexio.common.entity.BaseEntity;

/**
 * 定时任务实体
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@TableName("sys_scheduled_job")
public class ScheduledJob extends BaseEntity {
    
    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private String id;
    
    /**
     * 任务名称
     */
    @TableField("job_name")
    private String jobName;
    
    /**
     * 任务组
     */
    @TableField("job_group")
    private String jobGroup;
    
    /**
     * 任务描述
     */
    @TableField("description")
    private String description;
    
    /**
     * 任务处理器类名
     */
    @TableField("job_handler")
    private String jobHandler;
    
    /**
     * 任务参数 (JSON格式)
     */
    @TableField("job_params")
    private String jobParams;
    
    /**
     * Cron表达式
     */
    @TableField("cron_expression")
    private String cronExpression;
    
    /**
     * 任务状态
     */
    @TableField("status")
    private String status;
    
    /**
     * 执行次数
     */
    @TableField("execute_count")
    private Integer executeCount;
    
    /**
     * 成功次数
     */
    @TableField("success_count")
    private Integer successCount;
    
    /**
     * 失败次数
     */
    @TableField("fail_count")
    private Integer failCount;
    
    /**
     * 最后执行时间
     */
    @TableField("last_execute_time")
    private LocalDateTime lastExecuteTime;
    
    /**
     * 下次执行时间
     */
    @TableField("next_execute_time")
    private LocalDateTime nextExecuteTime;
    
    /**
     * 是否允许并发执行
     */
    @TableField("allow_concurrent")
    private Boolean allowConcurrent;
    
    /**
     * 最大重试次数
     */
    @TableField("max_retry_count")
    private Integer maxRetryCount;
    
    /**
     * 重试间隔 (秒)
     */
    @TableField("retry_interval")
    private Integer retryInterval;
    
    /**
     * 超时时间 (秒)
     */
    @TableField("timeout_seconds")
    private Integer timeoutSeconds;
    
    /**
     * 创建人
     */
    @TableField("creator")
    private String creator;
    
    // Constructors
    public ScheduledJob() {}
    
    public ScheduledJob(String jobName, String jobGroup, String jobHandler, String cronExpression) {
        this.jobName = jobName;
        this.jobGroup = jobGroup;
        this.jobHandler = jobHandler;
        this.cronExpression = cronExpression;
        this.status = "WAITING";
        this.executeCount = 0;
        this.successCount = 0;
        this.failCount = 0;
        this.allowConcurrent = false;
        this.maxRetryCount = 3;
        this.retryInterval = 60;
        this.timeoutSeconds = 300;
    }
    
    // Getters and Setters
    public String getId() { return id; }
    public void setId(String id) { this.id = id; }
    
    public String getJobName() { return jobName; }
    public void setJobName(String jobName) { this.jobName = jobName; }
    
    public String getJobGroup() { return jobGroup; }
    public void setJobGroup(String jobGroup) { this.jobGroup = jobGroup; }
    
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    
    public String getJobHandler() { return jobHandler; }
    public void setJobHandler(String jobHandler) { this.jobHandler = jobHandler; }
    
    public String getJobParams() { return jobParams; }
    public void setJobParams(String jobParams) { this.jobParams = jobParams; }
    
    public String getCronExpression() { return cronExpression; }
    public void setCronExpression(String cronExpression) { this.cronExpression = cronExpression; }
    
    public String getStatus() { return status; }
    public void setStatus(String status) { this.status = status; }
    
    public Integer getExecuteCount() { return executeCount; }
    public void setExecuteCount(Integer executeCount) { this.executeCount = executeCount; }
    
    public Integer getSuccessCount() { return successCount; }
    public void setSuccessCount(Integer successCount) { this.successCount = successCount; }
    
    public Integer getFailCount() { return failCount; }
    public void setFailCount(Integer failCount) { this.failCount = failCount; }
    
    public LocalDateTime getLastExecuteTime() { return lastExecuteTime; }
    public void setLastExecuteTime(LocalDateTime lastExecuteTime) { this.lastExecuteTime = lastExecuteTime; }
    
    public LocalDateTime getNextExecuteTime() { return nextExecuteTime; }
    public void setNextExecuteTime(LocalDateTime nextExecuteTime) { this.nextExecuteTime = nextExecuteTime; }
    
    public Boolean getAllowConcurrent() { return allowConcurrent; }
    public void setAllowConcurrent(Boolean allowConcurrent) { this.allowConcurrent = allowConcurrent; }
    
    public Integer getMaxRetryCount() { return maxRetryCount; }
    public void setMaxRetryCount(Integer maxRetryCount) { this.maxRetryCount = maxRetryCount; }
    
    public Integer getRetryInterval() { return retryInterval; }
    public void setRetryInterval(Integer retryInterval) { this.retryInterval = retryInterval; }
    
    public Integer getTimeoutSeconds() { return timeoutSeconds; }
    public void setTimeoutSeconds(Integer timeoutSeconds) { this.timeoutSeconds = timeoutSeconds; }
    
    public String getCreator() { return creator; }
    public void setCreator(String creator) { this.creator = creator; }
}
